package com.seveneight.baijiesteward.ui.main.model;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.seveneight.baijiesteward.bean.AnyBean;
import com.seveneight.baijiesteward.bean.BaseEntity;
import com.seveneight.baijiesteward.bean.UserConfigBean;
import com.seveneight.baijiesteward.http.BaseModel;
import com.seveneight.baijiesteward.http.BaseObserver;
import com.seveneight.baijiesteward.http.MyCallBack;
import com.seveneight.baijiesteward.http.RetrofitFactory;
import com.seveneight.baijiesteward.ui.main.contract.UserConfigContract;

import java.util.List;

import okhttp3.RequestBody;

/**
 * Created by user1 on 2018/3/30.
 */

public class UserConfigModel extends BaseModel implements UserConfigContract.UserConfigModel {

    @Override
    public void getUserConfig(Context context, RequestBody object, MyCallBack<List<UserConfigBean>> myCallBack) {
        RetrofitFactory.getInstence().API().getUserConfig(object).
                compose(this.<BaseEntity<AnyBean>>setThread()).
                subscribe(new BaseObserver<AnyBean>(context) {
                    @Override
                    protected void onSuccees(BaseEntity<AnyBean> t) throws Exception {
                        List<UserConfigBean> data = JSON.parseArray(t.getData().getConfigList(), UserConfigBean.class);
                        myCallBack.onSuccess(data);
                    }

                    @Override
                    protected void onFailure(Throwable e, boolean isNetWorkError) throws Exception {

                    }
                });
    }
}
